//
// Created by Tony on 2024/5/20.
//

#include "ModuleParser.h"

#include "../common/Utils.h"
#include "ast/list/module/Module.h"
#include <memory>

namespace Parser {

using std::make_shared;

shared_ptr<Ast> ModuleParser::parse() {
    vector<shared_ptr<Ast>> stmts;

    while (true) {
        auto token = tokenQueue.peek();
        if (token == nullptr || token->type() == Lexer::TokenType::EOF_T) {
            break;
        }
        auto stmt = this->stmt();
        CHECK_NULL_RETURN(stmt, nullptr);
        stmts.push_back(stmt);
    }

    return make_shared<Module>(stmts);
}

} // namespace Parser
